#pragma once
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

class INetAddr
{
private:
    void Init()
    {
        _ip = inet_ntoa(_in.sin_addr);
        _port = ntohs(_in.sin_port);
    }
public:
    INetAddr()
    {}
    INetAddr(struct sockaddr_in add)
        :_in(add)
    {
        Init();
    }
    INetAddr(const std::string& ip, uint16_t port)
        :_ip(ip), _port(port)
    {
        _in.sin_family = AF_INET;
        _in.sin_port = htons(_port);
        _in.sin_addr.s_addr = inet_addr(ip.c_str());
    }
    std::string IP() const
    {
        return _ip;
    }
    uint16_t Port() const
    {
        return _port;
    }
    struct sockaddr_in Addr() const
    {
        return _in;
    }
    bool operator==(const INetAddr& addr) const
    {
        if(_ip == addr._ip && _port == addr._port)
            return true;
        return false;
    }
    ~INetAddr()
    {}
private:
    struct sockaddr_in _in;
    std::string _ip;
    uint16_t _port;
};